package com.example.productmanagerspringboot.config;

import io.swagger.annotations.Api;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;


/**
 * 文档地址
 * http://localhost:8080/api/swagger-ui/
 * path : 表示参数放在地址栏中
 * query ：表示参数是以 key / value 的形式传递
 * body ：表示参数是放在请求体中
 */
@EnableOpenApi
@Configuration
public class SwaggerConfig {
    @Bean
    public Docket docket() {
        return new Docket(DocumentationType.OAS_30)
                .pathMapping("/")
                // 是否启用
                .enable(true)
                // Swagger UI 头部信息
                .apiInfo(apiInfo())
                // 指定生成文档的接口
                .select()
                .apis(RequestHandlerSelectors.withClassAnnotation(Api.class))
                .paths(PathSelectors.any())
                .build();
//                .apiInfo(apiInfo()).select()
//                .apis(RequestHandlerSelectors.basePackage("com"))
//                .paths(PathSelectors.any()).build();
    }

    public ApiInfo apiInfo() {
        return new ApiInfoBuilder().title("API").description("").version("0.1").build();
    }
}
